<?php
/**
 * Created by PhpStorm.
 * User: sunfan
 * Date: 2017/8/8
 * Time: 10:10
 */

namespace User\Controller;


use Common\Controller\AdminbaseController;
use Common\Model\BrandModel;
use Think\Page;

class BrandController extends AdminbaseController
{

    //  列表
    public function index(){
        $where = array();
        $count = D("Brand")->where($where)->count();
        $page = $this->page($count,$this->listRow);
        $this->assign('page',$page->show());
        $list = D("Brand")->where($where)->limit($page->firstRow.','.$page->listRows)->select();
        $this->assign('list',$list);
        $this->display();
    }

    // 添加
    public function add(){
        $model = new BrandModel();
        if(IS_POST){
          if(!$model->store()) $this->error($model->getError());
          $this->success("添加成",U('Brand/index'));
          exit();
        }
        $this->display();
    }


    //  编辑
    public function edit(){
        $model = new BrandModel();
        if(IS_POST){
            if(!$model->update()) $this->error($model->getError());
            $this->success('修改成功',U('Brand/index'));
            exit();
        }
        $id = I("get.id",0,'intval');
        $data = $model->where(array('id'=>$id))->find();
        $this->assign('data',$data);
        $this->display();
    }


}